package com.zb.select.controller;

import com.zb.entity.SelectVo;
import com.zb.result.PageUtil;
import com.zb.result.Result;
import com.zb.select.service.OrderSelecService;
import com.zb.service.*;
import com.zb.utils.TokenUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author WEN
 * @Date 2023/9/12 0012
 **/
@Api(tags = "工单下拉类接口")
@RestController
@RequestMapping("/order/select")
public class OrderSelectController {
    @Resource
    private OrderSelecService orderSelecService;
    @Resource
    private ZjWorkTeamService workTeamService;
    @Resource
    private ZjWorkLevelService workLevelService;
    @Resource
    private ZjWorkFeeProjectService workFeeProjectService;
    @Resource
    private ZjWorkModuleService workModuleService;
    @Resource
    private ZjWorkModuleTypeService workModuleTypeService;
    @Resource
    private ZjWorkModuleWayService workModuleWayService;
    @Resource
    private ZjWorkFieldService workFieldService;
    @Resource
    private ZjWorkClientStrategyService workClientStrategyService;
    @Resource
    private ZjWorkStatementTemplateService workStatementTemplateService;
    @Resource
    private ZjWorkSlaService workSlaService;

    @ApiOperation("工单客服组下拉列表查询")
    @PostMapping("/workTeamPageSelect")
    public Result workTeamPageSelect(HttpServletRequest request, @RequestBody SelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success().data(workTeamService.workTeamPageSelect(custAccId, selectVo));
    }

    @ApiOperation("工单级别下拉列表查询")
    @PostMapping("/workLevelPageSelect")
    public Result workLevelPageSelect(HttpServletRequest request, @RequestBody SelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success().data(workLevelService.workLevelPageSelect(custAccId, selectVo));
    }

    @ApiOperation("工单费用项目下拉列表查询")
    @PostMapping("/workFeeProjectPageSelect")
    public Result workFeeProjectPageSelect(HttpServletRequest request, @RequestBody SelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success().data(workFeeProjectService.workFeeProjectPageSelect(custAccId, selectVo));
    }

    @ApiOperation("工单模块下拉列表查询")
    @PostMapping("/workModulePageSelect")
    public Result workModulePageSelect(HttpServletRequest request, @RequestBody SelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        Map<String, Object> map;
        if (selectVo.getFactoryId() != null){
            map = workModuleService.workModulePageSelect(selectVo.getFactoryId());
        }else {
            map = workModuleService.workModulePageSelect(false, custAccId, selectVo);
        }
        return Result.success().data(map);
    }

    @ApiOperation("工单模块带费用下拉列表查询")
    @PostMapping("/workModulePricePageSelect")
    public Result workModulePricePageSelect(HttpServletRequest request, @RequestBody SelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success().data(workModuleService.workModulePricePageSelect(custAccId, selectVo));
    }

    @ApiOperation("工单模块分类下拉列表查询")
    @PostMapping("/workModuleTypePageSelect/{moduleId}")
    public Result workModuleTypePageSelect(@PathVariable @ApiParam(value = "工单模块ID", required = true) Long moduleId, @RequestBody SelectVo selectVo) {
        return Result.success().data(workModuleTypeService.workModuleTypePageSelect(moduleId, selectVo));
    }

    @ApiOperation("工单模块处理方式下拉列表查询")
    @PostMapping("/workModuleWayPageSelect/{moduleId}")
    public Result workModuleWayPageSelect(@PathVariable @ApiParam(value = "工单模块ID", required = true) Long moduleId, @RequestBody SelectVo selectVo) {
        return Result.success().data(workModuleWayService.workModuleWayPageSelect(moduleId, selectVo));
    }

    @ApiOperation("工单字段下拉列表查询")
    @PostMapping("/workFieldPageSelect")
    public Result workFieldPageSelect(HttpServletRequest request, @RequestBody SelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success().data(workFieldService.workFieldPageSelect(custAccId, selectVo));
    }

    @ApiOperation("客服分配规则下拉列表查询")
    @PostMapping("/workClientStrategyPageSelect")
    public Result workClientStrategyPageSelect(HttpServletRequest request, @RequestBody SelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success().data(workClientStrategyService.workClientStrategyPageSelect(custAccId, selectVo));
    }

    @ApiOperation("分页获取工单配件下拉数据列表")
    @PostMapping("/getOrderSparePageSelect/{workId}")
    public Result getOrderSparePageSelect(HttpServletRequest request, @PathVariable @ApiParam(value = "工单ID", required = true) Long workId, @RequestBody SelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("分页获取工单配件下拉数据列表成功").data(orderSelecService.getOrderSparePageSelect(custAccId, workId, selectVo));
    }

    @ApiOperation("分页获取工单配件规格下拉数据列表")
    @PostMapping("/getOrderSpareSpecSelect/{spareId}")
    public Result getOrderSpareSpecSelect(HttpServletRequest request, @PathVariable @ApiParam(value = "配件ID", required = true) Long spareId, @RequestBody SelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("分页获取工单配件规格下拉数据列表成功").data(orderSelecService.getOrderSpareSpecSelect(custAccId, spareId, selectVo));
    }

    @ApiOperation("获取结单模板下拉数据")
    @PostMapping("/getOrderFinishTemplateSelect")
    public Result getOrderFinishTemplateSelect(HttpServletRequest request, @RequestBody SelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("获取结单模板下拉数据成功").data(workStatementTemplateService.getOrderFinishTemplateSelect(custAccId, selectVo));
    }

    @ApiOperation("获取工单SLA下拉数据")
    @PostMapping("/getWorkSlaSelect")
    public Result getWorkSlaSelect(HttpServletRequest request, @RequestBody SelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("获取工单SLA下拉数据成功").data(workSlaService.getWorkSlaSelect(custAccId, selectVo));
    }



}
